#include <GL/glut.h>

#define CHECK_IMAGE_WIDTH 256
#define CHECK_IMAGE_HEIGHT 256
static GLubyte checkImage[CHECK_IMAGE_WIDTH][CHECK_IMAGE_HEIGHT][3];

void makeCheckImage(void) {

  int i, j, c;

  for (i = 0; i < CHECK_IMAGE_HEIGHT; i++)

    for (j = 0; j < CHECK_IMAGE_WIDTH; j++) {

      checkImage[i][j][0] = (GLubyte) 255;
      checkImage[i][j][1] = (GLubyte) i == j ? 255 : 0;
      checkImage[i][j][2] = (GLubyte) 255;

    }

}

void init() {
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glShadeModel(GL_FLAT);
  makeCheckImage();
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}

void display() {
  glClear(GL_COLOR_BUFFER_BIT);
  glRasterPos2i(0, 0);
  glDrawPixels(CHECK_IMAGE_WIDTH, CHECK_IMAGE_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, checkImage);
  glFlush();
}

void reshape(int w, int h) {
  gluOrtho2D(-10.0f, 10.0f, -10.0f, 10.0f);
  glViewport(-w, -h, 0, 0);
}

int main(int argc, char **argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB);
  glutCreateWindow(argv[0]);
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  init();
  glutMainLoop();
  return 0;
}
